package com.aaa.stock.service.impl;

import com.aaa.entity.StockProducer;

import com.aaa.stock.dao.ProducerDao;
import com.aaa.stock.service.ProducerService;
import com.aaa.stock.vo.ProducerVo;
import com.aaa.util.JwtUtil;
import com.aaa.util.WebUtil;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class ProducerServiceImpl extends ServiceImpl<ProducerDao,StockProducer> implements ProducerService {

    @Autowired
    private ProducerDao producerDao;

    @Override
    public Result<List<StockProducer>> getAll() {
        QueryWrapper<StockProducer> wrapper=new QueryWrapper<>();
        wrapper.eq("status",0);
        List<StockProducer> stockProviders = producerDao.selectList(wrapper);
        return new Result<>(2000,"查询",stockProviders);
    }

    @Override
    public Result<IPage<StockProducer>> getByPage(Integer currentPage, Integer pageSize, ProducerVo producerVo) {
        IPage<StockProducer> page=new Page<>(currentPage,pageSize);
        QueryWrapper<StockProducer>wrapper=new QueryWrapper<>();

        if (StringUtils.hasText(producerVo.getProducerName())){
            wrapper.like("producer_name",producerVo.getProducerName());
        }
        if (StringUtils.hasText(producerVo.getKeywords())){
            wrapper.like("keywords",producerVo.getKeywords());
        }
        if(Objects.nonNull(producerVo.getStatus())){
            wrapper.eq("status",producerVo.getStatus());
        }
        if(Objects.nonNull(producerVo.getDateRange())&&producerVo.getDateRange().length==2){
            wrapper.between("create_time",producerVo.getDateRange()[0],producerVo.getDateRange()[1]);
        }
        IPage<StockProducer>page1=producerDao.selectPage(page,wrapper);
        return new Result<>(2000,"查询",page1);
    }




}
